<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!doctype html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>LoveTemperature</title>
		<meta name="author" content="ningzero"/>

		<!-- CSS -->
		<link rel="stylesheet" href="../css/index.css">
		<!-- end CSS-->

	</head>

	<body>

		<div id="container">
			<header class="header">
				<div id="login_cart_bar">
					<div id="loginRegisterDiv">
						<s:if test="%{#session.user!=null}">
						欢迎惠顾，<s:property value="#session.user.name" />
						<a class="pinkAnchor" href="http://localhost:8080/lovetemperature/sale/logout">退出登录</a>
						</s:if>
						<s:else>
						<a class="pinkAnchor" onclick="showLoginDlg()">登录</a>
						<a class="pinkAnchor" onclick="showRegDlg()">注册</a>
						</s:else>
					</div>
					<div id="cartAccountDiv">
					<s:if test="%{#session.user!=null}">
						<a class="pinkAnchor" onclick="javascript:window.location='http://localhost:8080/lovetemperature/sale/showStepOne'">购物车</a>
						<a class="pinkAnchor" onclick="javascript:window.location='http://localhost:8080/lovetemperature/sale/showMember'">我的账户</a>
					</s:if>
					</div>
				</div>
				<div id="logo_bar">
					<img src="../img/logo.gif"/>
					<img id="logo_text" src="../img/logo2.png"/>
				</div>
				<div id="nav_bar">
					<ul>
						<li class="nav_padding_left"></li>
						<li class='<s:if test="%{#showCategory=='首页'}">shouye_cur</s:if><s:else>shouye</s:else>'>
							<a href="http://localhost:8080/lovetemperature/index">首页</a>
						</li>
						<li class='<s:if test="%{#showCategory=='蛋糕'}">dangao_cur</s:if><s:else>dangao</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=蛋糕">蛋糕</a>
						</li>
						<li class='<s:if test="%{#showCategory=='面包'}">mianbao_cur</s:if><s:else>mianbao</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=面包">面包</a>
						</li>
						<li class='<s:if test="%{#showCategory=='干点'}">gandian_cur</s:if><s:else>gandian</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=干点">干点</a>
						</li>
						<li class='<s:if test="%{#showCategory=='拌手礼'}">banshouli_cur</s:if><s:else>banshouli</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=拌手礼">伴手礼</a>
						</li>
						<li class='<s:if test="%{#showCategory=='饮品'}">kaquan_cur</s:if><s:else>kaquan</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=饮品">饮品</a>
						</li>
						<li class='<s:if test="%{#showCategory=='其他'}">qita_cur</s:if><s:else>qita</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=其他">其他</a>
						</li>
					</ul>
				</div>
			</header>
			<div id="mainContent" class="mainContent">
				<div id="goodsWrap">
					<div id="goodsBar">
						<span id="className"> 所有<s:property value="showCategory" /> </span>
					</div>
					
					<div id="goodsGallery">
						<table>
							<tbody>
								<s:iterator value="stockList" status="count">
								<!-- 一排商品start -->
								<s:if test="#count.index%4==0||#count.first">
								<tr>
								</s:if>
									<!-- 一件商品 start-->
									<td>
									<div class="good_pic">
										<a target="_blank" href="<s:property value="goodSet.good.image"/>" style=" width:150px;height:150px;"> <img src="<s:property value="goodSet.good.image"/>" alt="<s:property value="name"/>"> </a>
									</div>
									<div class="good_info">
										<div class="good_name">
											<s:property value="goodSet.good.name"/>
										</div>
										<div class="good_price">
											￥<s:property value="goodSet.good.price"/>
										</div>
										<div class="put_cart">
											<a target="_blank" onclick='addToCart(<s:property value="stockId"/>)'><img src="../img/btn_put_cart.gif" /></a>
										</div>
									</div></td>
									<!-- 一件商品 end-->
								<s:if test="#count.index%4==3||#count.last">
								</tr>
								</s:if>
								<!-- 一排商品end -->
								</s:iterator>
							</tbody>
						</table>
					</div>
				</div>
				
				<div id="saleGoods">
				</div>
				
			</div>
		</div>
		<!--! end of #container -->
		
		<footer id="footer">
			<img src="../img/tmp/tmpfooter.png" />
		</footer>

		<div id="loginDiv" class="dialog">
			<div id="LoginInputDiv">
				<h4>已注册用户，请登录</h4>
				<p>邮箱：<input type="text" id="account"/></p>
				<p>密码：<input type="password" id="password"/></p>
				<div id="loginBtn" class="normalBtn" onclick="login()">登录</div>
			</div>
			<div id="goRegDiv">
				<div class="closeBtnDiv">
					<div class="closeBtn" onclick="closeLoginDlg()">
						X
					</div>
				</div>
				<p>没有帐号？马上<a href="#">注册</a></p>
			</div>
		</div>
		
		<div id="registerDiv" class="dialog">
			<div id="RegInputDiv">
				<h4>用户注册</h4>
				<p>　用户名：<input type="text" id="memberName"/></p>
				<p>　　密码：<input type="password" id="passwordOne" /></p>
				<p>确认密码：<input type="password" id="passwordTwo"/></p>
				<p>电子邮箱：<input type="text" id="memberEmail"/></p>
				<div id="registerBtn" class="normalBtn" onclick="register()">注册</div>
			</div>
			<div id="goLoginDiv">
				<div class="closeBtnDiv">
					<div class="closeBtn" onclick="closeRegDlg()">
						X
					</div>
				</div>
				<p>已有帐号？马上<a href="#">登录</a></p>
			</div>
		</div>
		<!-- scripts -->
		<script type="text/javascript" src="../js/libs/jquery-1.9.1.min.js" ></script>
		<script type="text/javascript" src="../js/index.js" ></script>
		<script>
			$(function(){
				$('#loginDiv').hide();
				$('#registerDiv').hide();
			});
			function addCur() {
				$('#nav_bar li')
			}
			function login(){
				var account = $('#account').val();
				var password = $('#password').val();
				$.post("http://localhost:8080/lovetemperature/ajax/login",{
					"account":account,
					"password":password
				},function(data){
					alert(data.message);
					if(data.result=='memberSuccess'){
						window.location="http://localhost:8080/lovetemperature/index";
					}else if(data.result=='staffSuccess'){
						window.location="http://localhost:8080/lovetemperature/shop/showOrders";
					}else if(data.result=='adminSuccess'){
						window.location="http://localhost:8080/lovetemperature/sysadmin/showShop";
					}else if(data.result=='managerSuccess'){
						window.location="http://localhost:8080/lovetemperature/manage/memberStat";
					}
					$('#password').val("");
				},"json");
			}
			function register(){
				var name = $('#memberName').val();
				var passwordOne = $('#passwordOne').val();
				var passwordTwo = $('#passwordTwo').val();
				var email = $('#memberEmail').val();
				if(passwordOne != passwordTwo){
					alert("两次输入的密码不一样");
					return;
				}
				$.post("http://localhost:8080/lovetemperature/ajax/register",{
					"member.name":name,
					"member.password":passwordOne,
					"member.email":email
				},function(data){
					alert(data.message);
					if(data.result=='success'){
						location.reload();
					}
					$('#password').val("");
				},"json");
			}
			function addToCart(stockId){
				$.post("http://localhost:8080/lovetemperature/ajax/addToCart",{
					"stockId":stockId
				},function(data){
					alert(data.message);
				},"json");
			}
		</script>
		<!-- end scripts-->
	</body>
</html>
